#include <iostream>
#include <cstring>
#include "FrameClass.h"

auto pMOG2 = cv::createBackgroundSubtractorMOG2(50,300,false);

void process_frame(cv::Mat &image)
{
	cv::Mat mask,bg_image;
	pMOG2->apply(image,mask);
	pMOG2->getBackgroundImage(bg_image);

	cv::Mat se = getStructuringElement(cv::MORPH_RECT,cv::Size(1,5),cv::Point(-1,-1));
	cv::morphologyEx(mask,mask,cv::MORPH_OPEN,se);
	
	imshow("FG",mask);
	imshow("BG",bg_image);
}




int main(int argc,char** argv)
{
	bool ret = false;

	FrameClass* frameObj = new FrameClass();
#if 1	
	if(false == frameObj->OpenVideo(VIDEO_PATH)){
		delete frameObj;
		return 1;
	}
#endif

	while(true)
	{
#if 1	
		if(false == frameObj->ReadImage()){
			delete frameObj;
			return 2;
		}
#endif		
		//frameObj->SrcImg = cv::imread("./SaveImage/test_0.bmp");
		
		int val = cv::waitKey(30);
		if(KEYBOARD_1 == val){
			break;	
		}else if(KEYBOARD_2 == val){
			frameObj->SaveImage();
		}

		process_frame(frameObj->SrcImg);

		frameObj->SetROI(3,3);
		frameObj->SplitChannels(0);
		frameObj->Blur();
		frameObj->Threshold();
		frameObj->FindContours();
		frameObj->DrawContours();	

		frameObj->ShowSrcImage();
		frameObj->ShowRoiImage();
		frameObj->ShowChannelImage();
		frameObj->ShowBinaryImage();

		//cv::waitKey(0);
	}

	delete frameObj;	
	return 0;
}




